package cn.qingyun.gis.modules.express.service.impl;

import cn.hutool.core.text.CharSequenceUtil;
import cn.qingyun.gis.modules.express.entity.dto.ExpressInfoTotalDto;
import cn.qingyun.gis.modules.express.mapper.ExpressInfoTotalMapper;
import cn.qingyun.gis.modules.express.request.ExpressQueryRequest;
import cn.qingyun.gis.modules.express.service.IExpressInfoTotalService;
import cn.qingyun.gis.modules.init.system.constant.enums.RegionNumPermissionEnum;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
public class ExpressInfoTotalServiceImpl implements IExpressInfoTotalService {

    @Resource
    private ExpressInfoTotalMapper expressInfoTotalMapper;

    @Override
    public IPage<ExpressInfoTotalDto> queryTotalList(ExpressQueryRequest request) {
        //创建分页对象
        IPage<ExpressInfoTotalDto> page = new Page<>(request.getPageNum(), request.getPageSize());
        //左连接查询Page<ExpressInfoTotalDto>
        List<String> gridEncodings = Arrays.asList(request.getGridId().split(","));

        String gridType = request.getGridType();
        // 根据区域权限进行判定
        if (CharSequenceUtil.isNotEmpty(gridType) && RegionNumPermissionEnum.pitchRegion(request.getGridType())) {
            return page.setRecords(expressInfoTotalMapper.selectExpressTotalList(page, gridEncodings, gridType, request.getKeyword(), request.getLon(), request.getLat()));
        }
        return new Page<>();
    }

    @Override
    public ExpressInfoTotalDto queryProofreadById(String id) {
        return expressInfoTotalMapper.queryProofreadById(id);
    }


}
